package com.hspedu.exit_;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/2/15
 * @time 15:32
 */
public class ThreadExit_ {
    public static void main(String[] args) throws InterruptedException {
        T t = new T();
        t.start();

        Thread.sleep(10 * 1000);
        System.out.println("主线程苏醒");
        t.setLoop(false);
    }
}

class T extends Thread {

    private int count;

    /**
     * 设置一个变量
     */
    private boolean loop = true;

    @Override
    public void run() {

        while (loop) {

            try {
                /**
                 *  让当前线程休眠50ms
                 */
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("T 运行中...." + (++count));
        }
    }

    public void setLoop(boolean loop) {
        this.loop = loop;
    }
}

